#include "processeditorcommands.h"

#include "../editors/items/swpswimlanegraphicitem.h"

using namespace core;
using namespace swp;

AddSwimlaneCommand::AddSwimlaneCommand(GraphicData* data,
    SwpSwimlaneGraphicItem* item) :
        AddGraphicItemCommand(data, item),
        m_swimlane(item),
        m_previous(item->previous())
{
    setText(QObject::tr("Added swimlane"));
}

AddSwimlaneCommand::~AddSwimlaneCommand()
{

}

void AddSwimlaneCommand::undo()
{
    AddGraphicItemCommand::undo();

    if (m_previous != 0)
    {
        m_previous->setNext(0);
    }
}

void AddSwimlaneCommand::redo()
{
    AddGraphicItemCommand::redo();

    if (m_previous != 0)
    {
        m_swimlane->stackBefore(m_previous);
        m_previous->setNext(m_swimlane);
    }
}

RemoveSwimlaneCommand::RemoveSwimlaneCommand(GraphicData* data,
    SwpSwimlaneGraphicItem* item) :
        RemoveGraphicItemCommand(data, item),
        m_swimlane(item),
        m_previous(item->previous()),
        m_next(item->next())
{
    setText(QObject::tr("Removed swimlane"));
}

RemoveSwimlaneCommand::~RemoveSwimlaneCommand()
{

}

void RemoveSwimlaneCommand::undo()
{
    RemoveGraphicItemCommand::undo();

    if (m_previous != 0)
    {
        m_swimlane->stackBefore(m_previous);
        m_previous->setNext(m_swimlane);
    }

    if (m_next != 0)
    {
        m_next->setPrevious(m_swimlane);
    }
}

void RemoveSwimlaneCommand::redo()
{
    RemoveGraphicItemCommand::redo();

    if (m_previous != 0)
    {
        m_previous->setNext(m_next);
    }

    if (m_next != 0)
    {
        m_next->setPrevious(m_previous);
    }
}
